<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/23
 * Time: 17:45
 */

namespace app\api\controller;

use think\cache\driver\Redis;
use think\Controller;
use think\Db;
use think\Request;

class Base extends Controller{


    private $yjf = ['1'=>'元',2=>'角',3=>'分'];
    private $ret = ['kjjg'=>[],'num'=>'','time'=>''];
    public $redis = null;
    public function __construct(Request $request){

        parent::__construct($request);
        $this->redis = new Redis();

        //验证加密
        /*$VALUE_KEY = ['afewfewfew21342dsaewf'=>'8f4da4f9ew4f98ewq65fwe48f9w'];
        $HEADER_TIME = isset($_SERVER['HTTP_TIME']) ? $_SERVER['HTTP_TIME'] : '';
        $HEADER_KEY = isset($_SERVER['HTTP_KEY']) ? $_SERVER['HTTP_KEY'] : '';
        $HEADER_SIGN = isset($_SERVER['HTTP_SIGN']) ? $_SERVER['HTTP_SIGN'] : '';

        $POST_LOGIN_KEY = isset($_SERVER['HTTP_LOGINKEY']) ? $_SERVER['HTTP_LOGINKEY'] : ( isset($_POST['login_key']) ? $_POST['login_key'] : '' );
        $POST_NAME = isset($_SERVER['HTTP_USERNAME']) ? $_SERVER['HTTP_USERNAME'] : (isset($_POST['username']) ? $_POST['username'] : (isset($_POST['name']) ? $_POST['name']:''));


        if( !isset($VALUE_KEY[$HEADER_KEY]) ){
            exit(json_encode(['result'=>0], JSON_UNESCAPED_UNICODE));
        }

        $validation =  $HEADER_TIME.$VALUE_KEY[$HEADER_KEY].$POST_LOGIN_KEY.$POST_NAME;
        if( $HEADER_SIGN != md5($validation) ){
            exit(json_encode(['result'=>0], JSON_UNESCAPED_UNICODE));
        }*/
    }

    /**
     * 获得有结果的最新开奖信息
     * @param String $czid 彩种ID
     * @param String $time 当前时间
     * @return array
     */
    public function currentHasResult($czid,$time){
        $current_redis = $this->redis->get('result_'.$czid);
        if( $current_redis ){
            $current_arr = explode(',', $current_redis);
            $this->ret['kjjg'] = trim($current_arr[2]);
            $this->ret['num'] = $current_arr[0];
            $this->ret['time'] = $current_arr[1];
        }else{
            $current_detail = Db::name('kjjg_list')->where('czid',$czid)->where('jztime','<',$time)->where('kjjg','<>','0')->order('jztime','DESC')->find();
            $this->ret['kjjg'] = trim($current_detail['kjjg']);
            $this->ret['num'] = $current_detail['qihao'];
            $this->ret['time'] = $current_detail['jztime'];
        }
        return $this->ret;
    }
    /**
     * 获取最新一期的上一期期号(不管有无结果)
     * @param String $czid 彩种ID
     * @param String $time 当前时间
     * @return array
     */
    public function currentResult($czid,$time){

        $before_redis = $this->redis->get('secend_'.$czid);
        if($before_redis) {
            $this->ret['num'] = $before_redis;
            $detail = Db::name('kjjg_list')->where(['czid'=>$czid,'qihao'=>$before_redis])->field("qihao,kjjg,jztime")->find();
        }else{
            $detail = Db::name('kjjg_list')->where('czid',$czid)->where('jztime','<',$time)->field("qihao,kjjg,jztime")->order('jztime','DESC')->find();
        }
        if( $detail && "0"!=$detail['kjjg'] ){
            $this->ret['kjjg'] = trim($detail['kjjg']);
            $this->ret['num'] = $detail['qihao'];
            $this->ret['time'] = $detail['jztime'];
        }
        return $this->ret;
    }
    /**
     * 获取最新一期的上一期期号(不管有无结果)
     * @param String $czid 彩种ID
     * @return array
     */
    public function nextResult($czid){

        $next_redis = $this->redis->get($czid);
        if( $next_redis ){
            $next_arr = explode(',', $next_redis);
            $this->ret['num'] = $next_arr[0];
            $this->ret['time'] = $next_arr[1];
        }else{
            $next_detail = Db::name('kjjg_list')->where(['czid'=>$czid,'kjjg'=>0])->order('jztime','DESC')->find();
            if( $next_detail ){
                $this->ret['num'] = $next_detail['qihao'];
                $this->ret['time'] = $next_detail['jztime'];
            }
        }
        return $this->ret;
    }
    /**
     * 获取下一期期号
     * @param int $czid
     * @return string
     */
    protected function qihaoNext($czid){

    	$touzhuqihao = Db::name('kjjg_list')->where(['czid'=>$czid,'jztime'=>['<',time()]])->order('qihao','DESC')->find();
        $fp_time = Db::name('caipai_list')->where('id',$czid)->value('cp_fp_time');
        $touzhuqihao['qihao'] = $this->getTheoryPrevious($czid,$touzhuqihao['qihao'],$touzhuqihao['jztime'],$fp_time);
        $this->redis->set("secend_{$czid}", "{$touzhuqihao['qihao']}");

    	$tm = date('H:i:s',time() + $fp_time);

    	if( in_array($czid,[5,7,9,51]) ){
    		$sj = Db::name('time')->where('czid',$czid)->limit(1)->find();
    	}else{
    		$sj = Db::name('time')->where('czid',$czid)->where('jztime','>',$tm)->order('jztime','ASC')->limit(1)->find();
    	}
    	$time_min = Db::name('time')->field('MIN(qihao),czid')->group('czid')->column('qihao,jztime','czid');
    	$time_min_xyft = Db::name('time')->where(['czid'=>61])->field('qihao,jztime')->order("jztime ASC")->find();
        $time_min_xj11x5 = Db::name('time')->where(['czid'=>2])->field('qihao,jztime')->order("jztime ASC")->find();
    	if( empty($sj) ){
    		if( 61==intval($czid) ){//幸运飞艇
    			$sj['jztime'] = $time_min_xyft['jztime'];
    			$sj['qihao']  =$time_min_xyft['qihao'];
    		}elseif( 2==intval($czid) ){//11选5
                $sj['jztime'] = $time_min_xj11x5['jztime'];
                $sj['qihao']  =$time_min_xj11x5['qihao'];
            }elseif( 1==intval($czid) ){//重庆时时彩
    			$sj['jztime'] = '00:00:00';
    			$sj['qihao']  = '120';
    		}else{
    			$sj['jztime'] = $time_min[$czid]['jztime'];
    			$sj['qihao']  = $time_min[$czid]['qihao'];
    		}
            $sz_time = strtotime(date("Y-m-d",strtotime("+1 day")) . ' ' . $sj['jztime']);
    	}else {
    		$sz_time = strtotime(date('Y-m-d') . ' ' . $sj['jztime']);
    	}
        $qihao = '';
    	switch ( intval($czid) ) {
    		case 1:
    			//重庆时时彩
    			if ($sj['qihao'] < 10) $sj['qihao'] = '00' . $sj['qihao'];
    			if ($sj['qihao'] >= 10 && $sj['qihao'] < 100) $sj['qihao'] = '0' . $sj['qihao'];
    			$qihao = (120==intval($sj['qihao'])) ? date('Ymd', time()).$sj['qihao'] : date('Ymd', $sz_time).$sj['qihao'];
    			break;
            case 9:
                //香港六合彩
                if( time() < strtotime(date('Y-m-d 21:30:00',time())) ){
                    $calc_time = strtotime('-1 day');
                }else{
                    $calc_time = time();
                }
                $week = date("w", $calc_time);
                if ($week == '2' || $week == '4' || $week == '0') {   //星期2,4 日+2天
                    $sz_time = strtotime(date('Y-m-d', $calc_time + 2 * 24 * 3600) . ' ' . $sj['jztime']);
                }
                if ($week == '6') {   //星期6+3天
                    if((11==intval(date('m',$calc_time)) && 10==intval(date('d',$calc_time))) || (12==intval(date('m',$calc_time)) && 29==intval(date('d',$calc_time)))){
                        $sz_time = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' ' . $sj['jztime']);
                    }else{
                        $sz_time = strtotime(date('Y-m-d', $calc_time + 3 * 24 * 3600) . ' ' . $sj['jztime']);
                    }
                }
                if ($week == '1' || $week == '3' || $week == '5') {   //星期1,3,5+1天
                    $sz_time = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' ' . $sj['jztime']);
                }
                //11月10日，12月29日时延后一天
                $month = date('m',$sz_time);
                $day = date('d',$sz_time);
                if( (11==intval($month) && 10==intval($day)) || (12==intval($month) && 29==intval($day)) ){
                    $sz_time += 24*60*60;
                }

                $qihao_tmp = $touzhuqihao['qihao'] + 1;
                if (strlen($qihao_tmp) == strlen($touzhuqihao['qihao'])) {
                    $qihao = $qihao_tmp;
                } else {
                    $qihao = '0' . $qihao_tmp;
                }
                break;
            case 51:
                //七星彩
                if( time() < strtotime(date('Y-m-d 20:30:00')) ){
                    $calc_time = strtotime('-1 day');
                }else{
                    $calc_time = time();
                }
                $week = date("w", $calc_time);
                if ($week == '3' || $week == '5' || $week == '0') {   //星期3+2天
                    $sz_time = strtotime(date('Y-m-d', $calc_time + 2 * 24 * 3600) . ' ' . $sj['jztime']);
                }
                if ($week == '2') {   //星期2+3天
                    $sz_time = strtotime(date('Y-m-d', $calc_time + 3 * 24 * 3600) . ' ' . $sj['jztime']);
                }
                if ($week == '1' || $week == '4' || $week == '6') {   //星期4,6+1天
                    $sz_time = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' ' . $sj['jztime']);
                }
                $qihao_tmp = $touzhuqihao['qihao'] + 1;
                if (strlen($qihao_tmp) == strlen($touzhuqihao['qihao'])) {
                    $qihao = $qihao_tmp;
                } else {
                    $qihao = '0' . $qihao_tmp;
                }
                break;
    		case 62:
    			if ($sj['qihao'] == 0 && $sj['jztime'] = '00:00:00') {
    				$qihao = date('YmdHi', $sz_time);
    			} else {
    				$qihao = date('YmdHi', strtotime(date('Y-m-d') . $sj['jztime']));
    			}
    			break;
    		case 63:
    		case 72:
    			if($sj['qihao']==1440 && $data['jztime']='00:00:00') {
    				$qihao = date('Ymd',strtotime('-1 day')).$sj['qihao'];
    			}else{
    				if(strlen($sj['qihao'])==1){$sj['qihao'] = '000'.$sj['qihao'];}
    				if(strlen($sj['qihao'])==2){$sj['qihao'] = '00'.$sj['qihao'];}
    				if(strlen($sj['qihao'])==3){$sj['qihao'] = '0'.$sj['qihao'];}
    				$qihao = date('Ymd').$sj['qihao'];
    			}
    			break;
            case 39://甘肃快3  gsk3
            case 40://广西快3  gxk3
            case 41://贵州快3  gzk3
            case 43://湖北快3  hubk3
            //case 46://吉林快3
            case 47://上海快3  shk3
    		case 36://安徽快三
    		case 44://江苏快三
    		case 8://天津时时彩彩
            case 73://五分六合彩
    			if ($sj['qihao'] < 10) $sj['qihao'] = '00' . $sj['qihao'];
    			if ($sj['qihao'] >= 10 && $sj['qihao'] < 100) $sj['qihao'] = '0' . $sj['qihao'];
    			$qihao = date('Ymd', $sz_time) . $sj['qihao'];
    			break;
    		case 4:
    			//北京赛车
    		case 5:
    			//排列三
    		case 10:
    			//PC蛋蛋
    		case 7:
    			//上海时时乐
    			$qihao = $touzhuqihao['qihao'] + 1;
    			break;
    		case 16:
    			//广东11选5
    		case 28:
    			//山东11选5
            case 29: //上海11选5
    		case 48:
    			//上海时时乐
    		case 25:
    			//江西11选5
    			if ($sj['qihao'] < 10) {
    				$sj['qihao'] = '0' . $sj['qihao'];
    			}
                $qihao = date('Ymd', $sz_time) . $sj['qihao'];
    			break;
    		case 61:
    			//幸运飞艇
    			$cut_off = strtotime(date('Y-m-d').' '.'04:04:00');
    			if (time() < $cut_off) {
    				$sz_time = strtotime(date('Y-m-d', strtotime('-1 day')) . ' ' . $sj['jztime']);
    				$qihao = date('Ymd', $sz_time) . $sj['qihao'];
    			}elseif( time() > strtotime(date('Y-m-d').' '.'23:59:00') ){
                    $sz_time = strtotime(date('Y-m-d') . ' ' . $sj['jztime']);
    				$qihao = date('Ymd', $sz_time) . $sj['qihao'];
    			}else{
    				if ($sj['qihao'] < 10) $sj['qihao'] = '00' . $sj['qihao'];
    				if ($sj['qihao'] >= 10 && $sj['qihao'] < 100) $sj['qihao'] = '0' . $sj['qihao'];
    				$qihao = date('Ymd', $sz_time) . $sj['qihao'];
    			}
    			break;
            case 2:
                $cut_off = strtotime( date('Y-m-d').' 02:00:00' );
                if( time() <= $cut_off ){
                    $sztime = strtotime(date('Y-m-d', strtotime('-1 day')) . ' ' . $sj['jztime']);
                    $qihao = date('Ymd', $sztime).str_pad($sj['qihao'],3,"0",STR_PAD_LEFT);
                }else{
                    $qihao = date('Ymd', $sz_time) .str_pad($sj['qihao'],3,"0",STR_PAD_LEFT);
                }
                break;
    	}
        $between = $sz_time - $fp_time;
        $this->redis->set("{$czid}", "{$qihao},{$between},0");
    	return $qihao;
    }
    /**
     * 返回时时彩对应开奖结果后三内容
     * 组三，组六，豹子，顺子
     * @param $code
     * @return string
     */
    public function afterThree($code){
        $three = array_slice($code,2,3);
        $unique = count(array_unique($three));
        if( 1==$unique ){
            $label = '豹子';
        }elseif( 2==$unique ){
            $label = '组三';
        }else{
            sort($three);
            if( intval($three[0])+1==intval($three[1]) && intval($three[1])+1==intval($three[2]) ){
                $label = '顺子';
            }else{
                $label = '组六';
            }
        }
        return $label;
    }
    /**
     * 违规投注记录
     * @param $user
     * @param  string $tzhm 投注号码[G]元角分[G]金额[G]注数[G]投注总额[G]最高赔率[G]返点值[G]玩法ID[G]赔率ID[H]投注号码[G]元角分[G]金额[G]注数[G]投注总额[G]最高赔率[G]返点值[G]玩法ID[G]赔率ID
     * @param $qishu
     * @param $czname
     * @param string $violation
     * @param int $from
     */
    public function weigui_touzhu($user, $tzhm, $qishu, $czname, $violation = '',$from=0){
        file_put_contents("weigui.txt",date('Y-m-d H:i:s',time())."[0]{$from}[1]{$user}[2]{$tzhm}[3]{$qishu}[4]{$czname}[5]{$violation}".PHP_EOL,FILE_APPEND);
        $cztime = time();
        $cz_ip = get_ip();
        $newtouzhuz = '';
        $lottery_name = Db::name('caipai_list')->where('id', $czname)->find();
        if( empty($lottery_name) ){
            $jl_rizhi = "【违规投注:{$violation}】【无对应彩种】";
        }else{
            $lottery_name['cp_name_new'] || $lottery_name['cp_name_new'] = $lottery_name['cp_name_old'];
            $jubu_fenge_1 = explode('[H]', trim($tzhm,'[H]'));
            //投注号码[G]元角分[G]金额[G]注数[G]投注总额[G]最高赔率[G]返点值[G]玩法ID
            foreach ($jubu_fenge_1 as $k => $xh_1) {
                $k += 1;
                $jubu_fenge_3 = explode('[G]', $xh_1);
                if (count($jubu_fenge_3) == 9) {
                    $wf = Db::name("play_classify")->where(['id'=>$jubu_fenge_3[7]])->value('class_name_mini');
                    if( empty($wf) ) $wf = '未知';
                    $newtouzhuz .= "[{$k}]投注号码：{$jubu_fenge_3[0]}，圆角分模式：{$this->yjf[$jubu_fenge_3[1]]}，投注金额：{$jubu_fenge_3[2]}，投注注数：{$jubu_fenge_3[3]}，单注金额：{$jubu_fenge_3[4]}，当前赔率：{$jubu_fenge_3[5]}，选择返点：{$jubu_fenge_3[6]},玩法：{$wf}";
                } else {
                    $newtouzhuz .= "[{$k}]号码格式被修改，系统无法识别";
                }
            }
            $jl_rizhi = "【违规投注:{$violation}】【彩种：{$lottery_name['cp_name_new']}】【期数：{$qishu}】【投注号码：{$newtouzhuz}】";
        }
        //记录违规投注
        model('WeiguiJl')->setRecordOfViolation($user, $jl_rizhi, $cztime, $cz_ip);
        $count = Db::name('weigui_jl')->where('username', $user)->where('status',0)->count();
        //违规过多时锁定账号
        if ($count >= 5) {
            model('Username')->LockAccount($user);
            Db::name('frozen')->insert(array('username'=>$user,'frozen'=>'累计5次投注，账号冻结','djtime'=>time()));
        }
    }

    /**
     * 违规追号记录
     * @param $user
     * @param  string $tzhm 投注号码[G]元角分[G]金额[G]注数[G]投注总额[G]最高赔率[G]返点值[G]玩法ID[G]赔率ID[G]期号[H]投注号码[G]元角分[G]金额[G]注数[G]投注总额[G]最高赔率[G]返点值[G]玩法ID[G]赔率ID[G]期号
     * @param $czname
     * @param string $violation
     * @param int $from
     */
    public function weigui_zhuihao($user, $tzhm, $czname, $violation = '',$from=0){
        file_put_contents("zhuihao.txt",date('Y-m-d H:i:s',time())."[0]{$from}[1]{$user}[2]{$tzhm}[3]{$czname}[4]{$violation}".PHP_EOL,FILE_APPEND);
        $cztime = time();
        $cz_ip = get_ip();
        $newtouzhuz = '';
        $lottery_name = Db::name('caipai_list')->where('id', $czname)->find();
        if( empty($lottery_name) ){
            $jl_rizhi = "【违规追号:{$violation}】【无对应彩种】";
        }else{
            $lottery_name['cp_name_new'] || $lottery_name['cp_name_new'] = $lottery_name['cp_name_old'];
            $jubu_fenge_1 = explode('[H]', trim($tzhm,'[H]'));
            //投注号码[G]元角分[G]金额[G]注数[G]投注总额[G]最高赔率[G]返点值[G]玩法ID
            foreach ($jubu_fenge_1 as $k => $xh_1) {
                $k += 1;
                $jubu_fenge_3 = explode('[G]', $xh_1);
                if (count($jubu_fenge_3) == 10) {
                    $wf = Db::name("play_classify")->where(['id'=>$jubu_fenge_3[7]])->value('class_name_mini');
                    if( empty($wf) ) $wf = '未知';
                    $newtouzhuz .= "【期数：{$jubu_fenge_3[9]}】，[{$k}]投注号码：{$jubu_fenge_3[0]}，圆角分模式：{$this->yjf[$jubu_fenge_3[1]]}，投注金额：{$jubu_fenge_3[2]}，投注注数：{$jubu_fenge_3[3]}，单注金额：{$jubu_fenge_3[4]}，当前赔率：{$jubu_fenge_3[5]}，选择返点：{$jubu_fenge_3[6]},玩法：{$wf}";
                } else {
                    $newtouzhuz .= "[{$k}]号码格式被修改，系统无法识别";
                }
            }
            $jl_rizhi = "【违规追号:{$violation}】【彩种：{$lottery_name['cp_name_new']}】【投注号码：{$newtouzhuz}】";
        }
        //记录违规投注
        model('WeiguiJl')->setRecordOfViolation($user, $jl_rizhi, $cztime, $cz_ip);
        $count = Db::name('weigui_jl')->where('username', $user)->where('status',0)->count();
        //违规过多时锁定账号
        if ($count >= 5) {
            model('Username')->LockAccount($user);
        }
    }

    /**
     * 通过开奖结果结果计算注数
     * @param $wfid
     * @param $tzhm
     * @param $lottery_class_id
     * @return int
     */
    public function calc_zhushu($wfid,$tzhm,$lottery_class_id){

        $tzzs = 0;
        //统计投注位的个数
        $tzhm = explode(',',$tzhm);
        $hcount = array_map(function($v){
            $v = trim($v);
            if($v !== '') {
                return count(explode(' ',$v));
            } else {
                return 0;
            }
        },$tzhm);
        //第一位和第二位的交集
        $intersect = 0;
        if( 2==count($tzhm) ) {
            $arr_1 = explode(' ',trim($tzhm[0]));
            $arr_2 = explode(' ',trim($tzhm[1]));
            $intersect = count(array_intersect($arr_1,$arr_2));
        }
        switch(intval($lottery_class_id)){
            //快三
            case 2:
                switch( intval($wfid) ) {
                    case 105:
                        //和值
                        isset($hcount[0]) && $tzzs = $hcount[0];
                        break;
                    case 100:
                        //二同号复选
                        isset($hcount[0]) && $tzzs = $hcount[0];
                        break;
                    case 104:
                        //三连号通选
                        isset($hcount[0]) && !empty($hcount[0]) && $tzzs = 1;
                        break;
                    case 102:
                        //三同号单选
                        isset($hcount[0]) && $tzzs = $hcount[0];
                        break;
                    case 103:
                        //三同号通选
                        isset($hcount[0]) && !empty($hcount[0]) && $tzzs = 1;
                        break;
                    case 98:
                        //二不同号拖胆
                        isset($hcount[0]) && isset($hcount[1]) && $tzzs = $hcount[0] * $hcount[1];
                        break;
                    case 290:
                        //三不同号拖胆
                        if( isset($hcount[0]) && isset($hcount[1]) ){
                            2==$hcount[0] && $tzzs = $hcount[1];
                            1==$hcount[0] && $tzzs = $hcount[1]*($hcount[1]-1)/2;
                        }
                        break;
                    default:
                        $tzzs = 0;
                }
                break;
            case 1:
                //时时彩
                switch($wfid) {
                    case 1:
                        //五星直选复式
                        $tzzs = array_product($hcount);
                        break;
                    case 2:
                        //五星直选组合
                        $tzzs = 5 * array_product($hcount);
                        break;
                    case 3:
                        //五星组选120
                        $tzzs = $hcount[0] * ($hcount[0]-1) * ($hcount[0]-2) * ($hcount[0]-3) * ($hcount[0]-4) / 120;
                        break;
                    case 4:
                        //五星组选60
                        $tzzs = $hcount[0] * ($hcount[1]*($hcount[1]-1)*($hcount[1]-2)/6) - $intersect* ($hcount[1]-1) * ($hcount[1]-2) / 2;
                        break;
                    case 5:
                        //五星组选30
                        $tzzs = $hcount[1] * $hcount[0] * ($hcount[0]-1) / 2 - $intersect * ($hcount[0]-1);
                        break;
                    case 6:
                        //五星组选20
                        $tzzs = $hcount[0] * $hcount[1] * ($hcount[1]-1) / 2 - $intersect * ($hcount[1]-1);
                        break;
                    case 7:
                        //五星组选10
                        $tzzs = $hcount[0] * $hcount[1] - $intersect;
                        break;
                    case 8:
                        //五星组选5
                        $tzzs = $hcount[0] * $hcount[1] - $intersect;
                        break;
                    case 9:
                        //四星后四直选复式
                        $tzzs = array_product($hcount);
                        break;
                    case 10:
                        //四星后四直选组合
                        $tzzs = 4 * array_product($hcount);
                        break;
                    case 11:
                        //四星后四组选24
                        $tzzs = $hcount[0] * ($hcount[0]-1) * ($hcount[0]-2) * ($hcount[0]-3) / 24;
                        break;
                    case 12:
                        //四星后四组选12
                        $tzzs = $hcount[0] * $hcount[1] * ($hcount[1]-1)/2 - $intersect * ($hcount[1]-1);
                        break;
                    case 13:
                        //四星后四组选6
                        $tzzs = $hcount[0] * ($hcount[0]-1) / 2;
                        break;
                    case 14:
                        //四星后四组选4
                        $tzzs = $hcount[0] * $hcount[1] - $intersect;
                        break;
                    case 15:
                        //四星前四直选复式
                        $tzzs = array_product($hcount);
                        break;
                    case 16;
                        $tzzs = 4 * array_product($hcount);
                        break;
                    case 17:
                        //四星前四组选24
                        $tzzs = $hcount[0] * ($hcount[0]-1) * ($hcount[0]-2) * ($hcount[0]-3) / 24;
                        break;
                    case 18:
                        //四星前四组选12
                        $tzzs = $hcount[0] * $hcount[1] * ($hcount[1]-1)/2 - $intersect * ($hcount[1]-1);
                        break;
                    case 19:
                        //四星前四组选6
                        $tzzs = $hcount[0] * ($hcount[0]-1) / 2;
                        break;
                    case 20:
                        //四星前四组选4
                        $tzzs = $hcount[0] * $hcount[1] - $intersect;
                        break;
                    case 21:
                        //后三直选复式
                        $tzzs = array_product($hcount);
                        break;
                    case 22:
                        //后三直选和值
                        $tzzs = self::getDealCount( explode(' ',trim($tzhm[0])),22 );
                        break;
                    default:
                        $tzzs = 0;
                }
                break;
        }
        return $tzzs;
    }

    /**
     * 计算投注单号总金额
     * @param $number
     * @return float
     */
    public function calc_money($number){
        $total = 0;
        $list =explode('[H]',$number);
        foreach( $list as $v ){
            $detail = explode('[G]',$v);
            if( 9==count($detail) ){
                $single_money = floatval($detail[4]);
                if( '2'==$detail[1] ){
                    $single_money = floatval($detail[4])/10;
                }elseif( '3'==$detail[1] ){
                    $single_money = floatval($detail[4])/100;
                }
                $single_total = floatval($single_money)*intval($detail[3]);
                if( sprintf("%.2f",$single_total)==sprintf("%.2f",$detail[2]) ){
                    $total += $single_total;
                }
            }
        }
        return $total;
    }
    public function calc_zh_money($number){
        $total = 0;
        $list =explode('[H]',$number);
        foreach( $list as $v ){
            $detail = explode('[G]',$v);
            if( 10==count($detail) ){
                $single_money = floatval($detail[4]);
                if( '2'==$detail[1] ){
                    $single_money = floatval($detail[4])/10;
                }elseif( '3'==$detail[1] ){
                    $single_money = floatval($detail[4])/100;
                }
                $single_total = floatval($single_money)*intval($detail[3]);
                if( sprintf("%.2f",$single_total)==sprintf("%.2f",$detail[2]) ){
                    $total += $single_total;
                }
            }
        }
        return $total;
    }
    static function getDealCount($attr,$wfid){
        switch($wfid){
            case 22:
                $count = 0;
                foreach($attr as $vd) {
                    if($vd == '0' || $vd == '27') $count += 1;
                    if($vd == '1' || $vd == '26') $count += 3;
                    if($vd == '2' || $vd == '25') $count += 6;
                    if($vd == '3' || $vd == '24') $count += 10;
                    if($vd == '4' || $vd == '23') $count += 15;
                    if($vd == '5' || $vd == '22') $count += 21;
                    if($vd == '6' || $vd == '21') $count += 28;
                    if($vd == '7' || $vd == '20') $count += 36;
                    if($vd == '8' || $vd == '19') $count += 45;
                    if($vd == '9' || $vd == '18') $count += 55;
                    if($vd == '10' || $vd == '17') $count += 63;
                    if($vd == '11' || $vd == '16') $count += 69;
                    if($vd == '12' || $vd == '15') $count += 73;
                    if($vd == '13' || $vd == '14') $count += 75;
                }
                break;
            default:
                $count = 0;
        }
        return $count;
    }
    public function getTheoryPrevious($czid,$has_qh,$begin_time,$fp_time){
        //begin_time = 封盘时间 + 倒计时时间   45  46
        $count = Db::name('time')->where(['czid'=>$czid])->where(['jztime'=>['>',date('H:i:s',$begin_time+$fp_time)]])->where(['jztime'=>['<=',date('H:i:s',time()+$fp_time)]])->count();
        if( 0==$count ){
            return $has_qh;
        }else{
            if( in_array($czid,[4,5,7,9,10,51]) ){
                return $has_qh+1;
            }else{
                $tm = date('H:i:s',time() + $fp_time);
                $v = Db::name('time')->field("qihao,jztime,1 as type")->where(['czid'=>$czid,'jztime'=>['<=',$tm]])->order('jztime','DESC')->find();
                if(empty($v)){
                    $v = Db::name('time')->field("qihao,jztime,2 as type")->where('czid',$czid)->order('jztime','DESC')->find();
                }
                switch ( intval($czid) ) {
                    case 1:
                        ///重庆时时彩
                        if( 120 == intval($v['qihao'])){
                            if( time() > strtotime( date("Y-m-d 23:00:00",time()) ) ){
                                $v['qihao'] = date('Ymd',time()).'120';
                            }else{
                                $v['qihao'] = date('Ymd',strtotime("-1 day")).'120';
                            }
                        }else{
                            $v['qihao'] = date('Ymd',time()).str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                        }
                        break;
                    case 62:
                        //分分时时彩
                        if ( 0==intval($v['qihao']) ) {
                            if( time() > strtotime( date("Y-m-d 23:00:00",time()) ) ){
                                $v['qihao'] = date('YmdHi', strtotime(date('Y-m-d', strtotime('+1 day')) . $v['jztime']));
                            }else{
                                $v['qihao'] = date('YmdHi', strtotime(date('Y-m-d', time()) . $v['jztime']));
                            }
                        }else {
                            $v['qihao'] = date('YmdHi', strtotime(date('Y-m-d', time()) . $v['jztime']));
                        }
                        break;
                    case 63:
                        //极速PK10
                    case 72:
                        //极速快三
                        if( (1440==intval($v['qihao']))){
                            if( time() > strtotime( date("Y-m-d 23:00:00",time()) ) ){
                                $v['qihao'] = date('Ymd').$v['qihao'];
                            }else{
                                $v['qihao'] = date('Ymd',strtotime("-1 day")).$v['qihao'];
                            }
                        }else{
                            $v['qihao'] = date('Ymd',time()).str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                        }
                        break;
                    case 36://安徽快三
                    case 39://甘肃快3  gsk3
                    case 40://广西快3  gxk3
                    case 41://贵州快3  gzk3
                    case 43://湖北快3  hubk3
//                case 46://吉林快3
                    case 47://上海快3  shk3
                    case 44://江苏快三
                    case 8: //天津时时彩彩
                    case 73: //五分六合彩
                        if(1==$v['type']){
                            $v['qihao'] = date('Ymd').str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                        }else{
                            if( time() > strtotime( date("Y-m-d 21:00:00",time()) ) ){
                                $v['qihao'] = date('Ymd',time()).str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                            }else{
                                $v['qihao'] = date('Ymd',strtotime('-1 day')).str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                            }
                        }
                        break;
                    case 16:
                        //广东11选5
                    case 28:
                        //山东11选5
                    case 29: //上海11选5
                    case 48:
                        ///上海时时乐
                    case 25:
                        //江西11选5
                        if(1==$v['type']){
                            $v['qihao'] = date('Ymd').str_pad($v['qihao'],2,"0",STR_PAD_LEFT);
                        }else{
                            if( time() > strtotime( date("Y-m-d 21:00:00",time()) ) ){
                                $v['qihao'] = date('Ymd',time()).str_pad($v['qihao'],2,"0",STR_PAD_LEFT);
                            }else{
                                $v['qihao'] = date('Ymd',strtotime('-1 day')).str_pad($v['qihao'],2,"0",STR_PAD_LEFT);
                            }
                        }
                        break;
                    case 61:
                        //幸运飞艇
                        if(1==$v['type']){
                            if( intval($v['qihao']) > 131 ){
                                $v['qihao'] = date("Ymd",strtotime('-1 day')) . str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                            }else{
                                $v['qihao'] = date('Ymd') . str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                            }
                        }else{
                            //等于 131
                            if( time() > strtotime( date("Y-m-d 23:00:00",time()) ) ){
                                $v['qihao'] = date('Ymd') . str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                            }else{
                                $v['qihao'] = date("Ymd",strtotime('-1 day')) . str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                            }
                        }
                        break;
                    case 2:
                        //新疆时时彩
                        if(1==$v['type']){
                            if( intval($v['qihao']) >= 84 ){
                                $v['qihao'] = date("Ymd",strtotime('-1 day')) . str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                            }else{
                                $v['qihao'] = date('Ymd') . str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                            }
                        }else{
                            //等于 131
                            if( time() > strtotime( date("Y-m-d 23:00:00",time()) ) ){
                                $v['qihao'] = date('Ymd') . str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                            }else{
                                $v['qihao'] = date("Ymd",strtotime('-1 day')) . str_pad($v['qihao'],3,"0",STR_PAD_LEFT);
                            }
                        }
                        break;
                }
                return $v['qihao'];
            }
        }
    }
    protected function zhuihaoNext($czid,$limit=1){

        $qh = array();
        $previous = Db::name('kjjg_list')->where(['czid'=>$czid,'jztime'=>['<',time()]])->order('qihao','DESC')->find();
        $fp_time = Db::name("caipai_list")->where(['id'=>$czid])->value("cp_fp_time");
        $touzhuqihao['qihao'] = $this->getTheoryPrevious($czid,$previous['qihao'],$previous['jztime'],$fp_time);
        $touzhuqihao['qihao'] = intval($touzhuqihao['qihao']);

        $time = Db::name('caipai_list')->where('id',$czid)->field('time,cp_fp_time')->find();
        $tm = date('H:i:s',time()+$time['cp_fp_time']);
        $limit = $limit+2;
        if($czid==9){
            $sj = Db::name('time')->where('czid',$czid)->limit(1)->select();
        }else{
            $sj = Db::name('time')->where('czid',$czid)->where('jztime','>',$tm)->order('jztime','ASC')->limit($limit)->select();
        }
//        $time_min = Db::name('time')->field('MIN(qihao),czid')->group('czid')->column('qihao,jztime','czid');
//        $time_min_xyft = Db::name('time')->where(['czid'=>61])->field('qihao,jztime')->order("jztime ASC")->find();
//        $xyft_time_qh = Db::name('time')->where(['czid'=>61])->column("jztime,qihao");
        if( !empty($sj) ){
            foreach ($sj as $key=>$val){
//                if(empty($sj)){
//                    if( 61==intval($czid) ){//幸运飞艇
//                        $val['jztime'] = $time_min_xyft['jztime'];
//                        $val['qihao']  =$time_min_xyft['qihao'];
//                    }elseif( 1==intval($czid) ){//重庆时时彩
//                        $val['jztime'] = '00:00:00';
//                        $val['qihao']  = '120';
//                    }else{
//                        $val['jztime'] = $time_min[$czid]['jztime'];
//                        $val['qihao']  = $time_min[$czid]['qihao'];
//                    }
//                    $sz_time = strtotime(date("Y-m-d",strtotime("+1 day")) . ' ' . $val['jztime']);
//                }else {
                    $sz_time = strtotime(date("Y-m-d") . ' ' . $val['jztime']);
//                }
                switch ( intval($czid) ) {
                    case 1:
                        //重庆时时彩
                        if ($val['qihao'] < 10) $val['qihao'] = '00' . $val['qihao'];
                        if ($val['qihao'] >= 10 && $val['qihao'] < 100) $val['qihao'] = '0' . $val['qihao'];
                        $qihao = (120==intval($val['qihao'])) ? date('Ymd', time()).$val['qihao'] : date('Ymd', $sz_time).$val['qihao'];
                        break;
                    case 9:
                        //香港六合彩
                        if( time() < strtotime(date('Y-m-d 21:30:00',time())) ){
                            $calc_time = strtotime('-1 day');
                        }else{
                            $calc_time = time();
                        }
                        $week = date("w", $calc_time);
                        if ($week == '2' || $week == '4' || $week == '0') {   //星期2,4 日+2天
                            $sz_time = strtotime(date('Y-m-d', $calc_time + 2 * 24 * 3600) . ' ' . $val['jztime']);
                        }
                        if ($week == '6') {   //星期6+3天
                            if((11==intval(date('m',$calc_time)) && 10==intval(date('d',$calc_time))) || (12==intval(date('m',$calc_time)) && 29==intval(date('d',$calc_time)))){
                                $sz_time = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' ' . $val['jztime']);
                            }else{
                                $sz_time = strtotime(date('Y-m-d', $calc_time + 3 * 24 * 3600) . ' ' . $val['jztime']);
                            }
                        }
                        if ($week == '1' || $week == '3' || $week == '5') {   //星期1,3,5+1天
                            $sz_time = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' ' . $val['jztime']);
                        }

                        //11月10日，12月29日时延后一天
                        $month = date('m',$sz_time);
                        $day = date('d',$sz_time);
                        if( (11==intval($month) && 10==intval($day)) || (12==intval($month) && 29==intval($day)) ){
                            $sz_time += 24*60*60;
                        }

                        $qihao_tmp = $touzhuqihao['qihao'] + 1;
                        if (strlen($qihao_tmp) == strlen($touzhuqihao['qihao'])) {
                            $qihao = $qihao_tmp;
                        } else {
                            $qihao = '0' . $qihao_tmp;
                        }
                        break;
                    case 51:
                        //七星彩
                        if( time() < strtotime(date('Y-m-d 20:30:00',time())) ){
                            $calc_time = strtotime('-1 day');
                        }else{
                            $calc_time = time();
                        }
                        $week = date("w", $calc_time);

                        if ($week == '3' || $week == '5' || $week == '0') {   //星期3+2天
                            $sz_time = strtotime(date('Y-m-d', $calc_time + 2 * 24 * 3600) . ' ' . $val['jztime']);
                        }
                        if ($week == '2') {   //星期2+3天
                            $sz_time = strtotime(date('Y-m-d', $calc_time + 3 * 24 * 3600) . ' ' . $val['jztime']);
                        }
                        if ($week == '1' || $week == '4' || $week == '6') {   //星期4,6+1天
                            $sz_time = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' ' . $val['jztime']);
                        }
                        $qihao_tmp = $touzhuqihao['qihao'] + 1;
                        if (strlen($qihao_tmp) == strlen($touzhuqihao['qihao'])) {
                            $qihao = $qihao_tmp;
                        } else {
                            $qihao = '0' . $qihao_tmp;
                        }

                        break;
                    case 62:
                        if ($val['qihao'] == 0 && $val['jztime'] = '00:00:00') {
                            $qihao = date('YmdHi', $sz_time);
                        } else {
                            $qihao = date('YmdHi', strtotime(date('Y-m-d') . $val['jztime']));
                        }
                        break;
                    case 63:

                    case 72:
                        if($val['qihao']==1440 && $data['jztime']='00:00:00') {
                            $qihao = date('Ymd',strtotime('-1 day')).$val['qihao'];
                        }else{
                            if(strlen($val['qihao'])==1){$val['qihao'] = '000'.$val['qihao'];}
                            if(strlen($val['qihao'])==2){$val['qihao'] = '00'.$val['qihao'];}
                            if(strlen($val['qihao'])==3){$val['qihao'] = '0'.$val['qihao'];}
                            $qihao = date('Ymd').$val['qihao'];
                        }
                        break;
                    case 36://安徽快三
                    case 39://甘肃快3  gsk3
                    case 40://广西快3  gxk3
                    case 41://贵州快3  gzk3
                    case 43://湖北快3  hubk3
//                case 46://吉林快3
                    case 47://上海快3  shk3
                    case 44://江苏快三
                    case 8: //天津时时彩彩
                    case 73: //五分六合彩
                        if ($val['qihao'] < 10) $val['qihao'] = '00' . $val['qihao'];
                        if ($val['qihao'] >= 10 && $val['qihao'] < 100) $val['qihao'] = '0' . $val['qihao'];
                        $qihao = date('Ymd', $sz_time) . $val['qihao'];
                        break;
                    case 4:
                        //北京赛车
                    case 5:
                        //排列三
                    case 10:
                        //PC蛋蛋
                    case 7:
                        //福彩3D
                        $qihao_tmp = $touzhuqihao['qihao'] + 1+$key;
                        if (strlen($qihao_tmp) == strlen($touzhuqihao['qihao'])) {
                            $qihao = $qihao_tmp;
                        } else {
                            $qihao = '0' . $qihao_tmp;
                        }
                        break;

                    case 16:
                        //广东11选5
                    case 28:
                        //山东11选5
                    case 29: //上海11选5
                    case 48:
                        //上海时时乐
                    case 25:
                        //江西11选5
                        if ($val['qihao'] < 10) {
                            $val['qihao'] = '0' . $val['qihao'];
                        }
                        $qihao = date('Ymd',$sz_time) . $val['qihao'];
                        break;
                    case 61:
                        //幸运飞艇
                        $cut_off = strtotime(date('Y-m-d').' '.'04:04:00');
                        if (time() < $cut_off) {
                            $sztime = strtotime(date('Y-m-d', strtotime('-1 day')) . ' ' . $val['jztime']);
                            $qihao = date('Ymd', $sztime) . $val['qihao'];
                        }elseif( time() > strtotime(date('Y-m-d').' '.'23:59:00') ){
                            $sztime = strtotime(date('Y-m-d') . ' ' . $val['jztime']);
                            $qihao = date('Ymd', $sztime) . $val['qihao'];
                        }else{
                            if ($val['qihao'] < 10) $val['qihao'] = '00' . $val['qihao'];
                            if ($val['qihao'] >= 10 && $val['qihao'] < 100) $val['qihao'] = '0' . $val['qihao'];
                            $qihao = date('Ymd', $sz_time) . $val['qihao'];
                        }
                        break;
                    case 2:
                        //新疆时时彩
                        $cut_off = strtotime( date('Y-m-d').' 02:00:00' );
                        if (time() <= $cut_off) {
                            $sztime = strtotime(date('Y-m-d', strtotime('-1 day')) . ' ' . $val['jztime']);
                            $qihao = date('Ymd', $sztime).str_pad($val['qihao'],3,"0",STR_PAD_LEFT);
                        }else{
                            $qihao = date('Ymd', $sz_time) .str_pad($val['qihao'],3,"0",STR_PAD_LEFT);
                        }
                        break;
                }
                $qh[]= $qihao;
            }
        }
        return $qh;

    }
    protected function zhuihaoNext_new($czid,$limit=1){

        $qh = array();
        $previous = Db::name('kjjg_list')->where(['czid'=>$czid,'jztime'=>['<',time()]])->order('qihao','DESC')->find();
 
        $fp_time = Db::name("caipai_list")->where(['id'=>$czid])->value("cp_fp_time");
        $touzhuqihao['qihao'] = $this->getTheoryPrevious($czid,$previous['qihao'],$previous['jztime'],$fp_time);
        $touzhuqihao['qihao'] = intval($touzhuqihao['qihao']);

        $time = Db::name('caipai_list')->where('id',$czid)->field('time,cp_fp_time')->find();
        if($czid==62 || $czid==63 || $czid==73){
            $tm = date('H:i:s',time()+$time['time']);
        }else{
            $tm = date('H:i:s',time()+$time['cp_fp_time']);
        }
        $limit = $limit;
        if($czid==9){
            $sj = Db::name('time')->where('czid',$czid)->limit(1)->select();
        }else{
            $sj = Db::name('time')->where('czid',$czid)->where('jztime','>',$tm)->order('jztime','ASC')->limit($limit)->select();
        }
//        $time_min = Db::name('time')->field('MIN(qihao),czid')->group('czid')->column('qihao,jztime','czid');
//        $time_min_xyft = Db::name('time')->where(['czid'=>61])->field('qihao,jztime')->order("jztime ASC")->find();
//        $xyft_time_qh = Db::name('time')->where(['czid'=>61])->column("jztime,qihao");
        if( !empty($sj) ){
            foreach ($sj as $key=>$val){
//                if(empty($sj)){
//                    if( 61==intval($czid) ){//幸运飞艇
//                        $val['jztime'] = $time_min_xyft['jztime'];
//                        $val['qihao']  =$time_min_xyft['qihao'];
//                    }elseif( 1==intval($czid) ){//重庆时时彩
//                        $val['jztime'] = '00:00:00';
//                        $val['qihao']  = '120';
//                    }else{
//                        $val['jztime'] = $time_min[$czid]['jztime'];
//                        $val['qihao']  = $time_min[$czid]['qihao'];
//                    }
//                    $sz_time = strtotime(date("Y-m-d",strtotime("+1 day")) . ' ' . $val['jztime']);
//                }else {
                    $sz_time = strtotime(date("Y-m-d") . ' ' . $val['jztime']);
//                }
                switch ( intval($czid) ) {
                    case 1:
                        //重庆时时彩
                        if ($val['qihao'] < 10) $val['qihao'] = '00' . $val['qihao'];
                        if ($val['qihao'] >= 10 && $val['qihao'] < 100) $val['qihao'] = '0' . $val['qihao'];
                        $qihao = (120==intval($val['qihao'])) ? date('Ymd', time()).$val['qihao'] : date('Ymd', $sz_time).$val['qihao'];
                        break;
                    case 9:
                        //香港六合彩
                        if( time() < strtotime(date('Y-m-d 21:30:00',time())) ){
                            $calc_time = strtotime('-1 day');
                        }else{
                            $calc_time = time();
                        }
                        $week = date("w", $calc_time);
                        if ($week == '2' || $week == '4' || $week == '0') {   //星期2,4 日+2天
                            $sz_time = strtotime(date('Y-m-d', $calc_time + 2 * 24 * 3600) . ' ' . $val['jztime']);
                        }
                        if ($week == '6') {   //星期6+3天
                            if((11==intval(date('m',$calc_time)) && 10==intval(date('d',$calc_time))) || (12==intval(date('m',$calc_time)) && 29==intval(date('d',$calc_time)))){
                                $sz_time = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' ' . $val['jztime']);
                            }else{
                                $sz_time = strtotime(date('Y-m-d', $calc_time + 3 * 24 * 3600) . ' ' . $val['jztime']);
                            }
                        }
                        if ($week == '1' || $week == '3' || $week == '5') {   //星期1,3,5+1天
                            $sz_time = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' ' . $val['jztime']);
                        }

                        //11月10日，12月29日时延后一天
                        $month = date('m',$sz_time);
                        $day = date('d',$sz_time);
                        if( (11==intval($month) && 10==intval($day)) || (12==intval($month) && 29==intval($day)) ){
                            $sz_time += 24*60*60;
                        }

                        $qihao_tmp = $touzhuqihao['qihao'] + 1;
                        if (strlen($qihao_tmp) == strlen($touzhuqihao['qihao'])) {
                            $qihao = $qihao_tmp;
                        } else {
                            $qihao = '0' . $qihao_tmp;
                        }
                        break;
                    case 51:
                        //七星彩
                        if( time() < strtotime(date('Y-m-d 20:30:00',time())) ){
                            $calc_time = strtotime('-1 day');
                        }else{
                            $calc_time = time();
                        }
                        $week = date("w", $calc_time);

                        if ($week == '3' || $week == '5' || $week == '0') {   //星期3+2天
                            $sz_time = strtotime(date('Y-m-d', $calc_time + 2 * 24 * 3600) . ' ' . $val['jztime']);
                        }
                        if ($week == '2') {   //星期2+3天
                            $sz_time = strtotime(date('Y-m-d', $calc_time + 3 * 24 * 3600) . ' ' . $val['jztime']);
                        }
                        if ($week == '1' || $week == '4' || $week == '6') {   //星期4,6+1天
                            $sz_time = strtotime(date('Y-m-d', $calc_time + 1 * 24 * 3600) . ' ' . $val['jztime']);
                        }
                        $qihao_tmp = $touzhuqihao['qihao'] + 1;
                        if (strlen($qihao_tmp) == strlen($touzhuqihao['qihao'])) {
                            $qihao = $qihao_tmp;
                        } else {
                            $qihao = '0' . $qihao_tmp;
                        }

                        break;
                    case 62:
                        if ($val['qihao'] == 0 && $val['jztime'] = '00:00:00') {
                            $qihao = date('YmdHi', $sz_time);
                        } else {
                            $qihao = date('YmdHi', strtotime(date('Y-m-d') . $val['jztime']));
                        }
                        break;
                    case 63:

                    case 72:
                        if($val['qihao']==1440 && $data['jztime']='00:00:00') {
                            $qihao = date('Ymd',strtotime('-1 day')).$val['qihao'];
                        }else{
                            if(strlen($val['qihao'])==1){$val['qihao'] = '000'.$val['qihao'];}
                            if(strlen($val['qihao'])==2){$val['qihao'] = '00'.$val['qihao'];}
                            if(strlen($val['qihao'])==3){$val['qihao'] = '0'.$val['qihao'];}
                            $qihao = date('Ymd').$val['qihao'];
                        }
                        break;
                    case 36://安徽快三
                    case 39://甘肃快3  gsk3
                    case 40://广西快3  gxk3
                    case 41://贵州快3  gzk3
                    case 43://湖北快3  hubk3
//                case 46://吉林快3
                    case 47://上海快3  shk3
                    case 44://江苏快三
                    case 8: //天津时时彩彩
                    case 73: //五分六合彩
                        if ($val['qihao'] < 10) $val['qihao'] = '00' . $val['qihao'];
                        if ($val['qihao'] >= 10 && $val['qihao'] < 100) $val['qihao'] = '0' . $val['qihao'];
                        $qihao = date('Ymd', $sz_time) . $val['qihao'];
                        break;
                    case 4:
                        //北京赛车
                    case 5:
                        //排列三
                    case 10:
                        //PC蛋蛋
                    case 7:
                        //福彩3D
                        $qihao_tmp = $touzhuqihao['qihao'] + 1+$key;
                        if (strlen($qihao_tmp) == strlen($touzhuqihao['qihao'])) {
                            $qihao = $qihao_tmp;
                        } else {
                            $qihao = '0' . $qihao_tmp;
                        }
                        break;

                    case 16:
                        //广东11选5
                    case 28:
                        //山东11选5
                    case 29: //上海11选5
                    case 48:
                        //上海时时乐
                    case 25:
                        //江西11选5
                        if ($val['qihao'] < 10) {
                            $val['qihao'] = '0' . $val['qihao'];
                        }
                        $qihao = date('Ymd',$sz_time) . $val['qihao'];
                        break;
                    case 61:
                        //幸运飞艇
                        $cut_off = strtotime(date('Y-m-d').' '.'04:04:00');
                        if (time() < $cut_off) {
                            $sztime = strtotime(date('Y-m-d', strtotime('-1 day')) . ' ' . $val['jztime']);
                            $qihao = date('Ymd', $sztime) . $val['qihao'];
                        }elseif( time() > strtotime(date('Y-m-d').' '.'23:59:00') ){
                            $sztime = strtotime(date('Y-m-d') . ' ' . $val['jztime']);
                            $qihao = date('Ymd', $sztime) . $val['qihao'];
                        }else{
                            if ($val['qihao'] < 10) $val['qihao'] = '00' . $val['qihao'];
                            if ($val['qihao'] >= 10 && $val['qihao'] < 100) $val['qihao'] = '0' . $val['qihao'];
                            $qihao = date('Ymd', $sz_time) . $val['qihao'];
                        }
                        break;
                    case 2:
                        //新疆时时彩
                        $cut_off = strtotime( date('Y-m-d').' 02:00:00' );
                        if (time() <= $cut_off) {
                            $sztime = strtotime(date('Y-m-d', strtotime('-1 day')) . ' ' . $val['jztime']);
                            $qihao = date('Ymd', $sztime).str_pad($val['qihao'],3,"0",STR_PAD_LEFT);
                        }else{
                            $qihao = date('Ymd', $sz_time) .str_pad($val['qihao'],3,"0",STR_PAD_LEFT);
                        }
                        break;
                }
                $qh[]= $qihao;
            }
        }
        return $qh;

    }
}